<?php
$title='系统管理';
define('IN_TG', 'admin_system');
include('admin_header.php');
$sql = "select * from tg_system limit 1";
$row = _fetch_array($sql);
?>
<div class="row">
    <div class="col-lg-12">
        <h1>多用户留言 <small>后台管理系统</small></h1>
        <ol class="breadcrumb">
            <li><a href="admin_index.php"><i class="fa fa-home"></i> 首页</a></li>
            <li class="active"><i class="fa fa-table"></i> <?php echo $title;?></li>
        </ol>
        <div class="alert alert-danger alert-dismissable" id="system_warming_alert" style="display: none">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            <span id="system_warming"></span>
        </div>
    </div>
</div><!-- /.row -->

<div class="row">
    <div class="col-lg-12">
        <form role="form" style="overflow: hidden">
            <fieldset>
                <legend><h2>系统参数</h2></legend>
                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-6">
                    <div class="form-group input-group">
                        <span class="input-group-addon">系统</span>
                        <input type="text" id="webname" class="form-control" value="<?php echo $row['tg_webname'];?>">
                    </div>
                </div>
                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-6">
                    <div class="form-group input-group">
                        <span class="input-group-addon">文章分页数</span>
                        <input type="number" id="article_num" class="form-control" value="<?php echo $row['tg_article'];?>" step="5" min="5" max="30">
                    </div>
                </div>
                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-6">
                    <div class="form-group input-group">
                        <span class="input-group-addon">博友分页数</span>
                        <input type="number" id="blog_num" class="form-control" value="<?php echo $row['tg_blog'];?>" step="5" min="5" max="30">
                    </div>
                </div>
                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-6">
                    <div class="form-group input-group">
                        <span class="input-group-addon">相册分页数</span>
                        <input type="number" id="photo_num" class="form-control" value="<?php echo $row['tg_blog'];?>" step="5" min="5" max="30">
                    </div>
                </div>
                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-6">
                    <div class="form-group input-group">
                        <span class="input-group-addon">默认皮肤</span>
                        <input type="number" id="skin_num" class="form-control" value="<?php echo $row['tg_skin'];?>" min="1" max="3">
                    </div>
                </div>
                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-6">
                    <div class="form-group input-group">
                        <span class="input-group-addon">发帖间隙时间</span>
                        <input type="number" id="post_num" class="form-control" value="<?php echo $row['tg_post'];?>" min="0" max="100" step="10">
                    </div>
                </div>
                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-6">
                    <div class="form-group input-group">
                        <span class="input-group-addon">回帖间隔时间</span>
                        <input type="number" id="reply_num" class="form-control" value="<?php echo $row['tg_re'];?>" min="0" max="100" step="10">
                    </div>
                </div>
                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-6">
                    <button type="button" class="btn btn-primary" id="sumbit_change_system">提交修改</button>
                </div>
            </fieldset>
        </form>
    </div>
    <div class="col-lg-12" style="margin-top: 10px;">
        <form role="form" style="overflow: hidden">
            <fieldset id="word-form">
                <legend><h2>敏感词管理</h2></legend>
            <?php $word_arr=explode('|',$row['tg_string']);
            foreach($word_arr as $item):?>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6 word-col">
                    <div class="form-group input-group">
                        <input type="text" class="word_item form-control" value="<?php echo $item;?>">
                        <span class="input-group-btn  chk_word" data-word="<?php echo $item;?>"><button type="button" class="btn btn-success"><i class=" fa fa-check"></i></button></span>
                        <span class="input-group-btn del_word" data-word="<?php echo $item; ?>"><button type="button"
                                                                                                        class="btn btn-danger"><i
                                    class="fa fa-times"></i></button></span>
                    </div>
                </div>
            <?php endforeach;?>
            </fieldset>
        </form>
    </div>
    <div class="col-lg-12" style="margin-top: 10px;overflow: hidden">
        <form role="form" style="overflow: hidden">
            <fieldset>
                <legend><h2>敏感词增加</h2></legend>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <div class="form-group input-group">
                        <input type="text" id="word_item" class="form-control" value="">
                        <span class="input-group-btn add_word"><button class="btn btn-primary" type="button"><i
                                    class=" fa fa-plus"></i></button></span>
                    </div>
                </div>
            </fieldset>
        </form>
    </div>
</div><!-- /.row -->



</div><!-- /#page-wrapper -->
<?php include('admin_footer.php');?>
<script>
    $(function(){
        $("#admin_system").attr('class','active');
        //系统信息修改
        $("#sumbit_change_system").click(function(){
            //默认隐藏错误提示框
            $("#system_warming_alert").hide();
            //取得 系统名
            var webname=$("#webname").val();
            //取得 文章分页数
            var article_num=$("#article_num").val();
            //取得 博友分页数
            var blog_num=$("#blog_num").val();
            //取得 相片分页数
            var photo_num=$("#photo_num").val();
            //取得 默认皮肤
            var skin_num=$("#skin_num").val();
            //取得 发帖间隙时间
            var post_num=$("#post_num").val();
            //取得 回帖间隔时间
            var reply_num=$("#reply_num").val();

            $.ajax({
                type:'post',
                url:'admin_action.php',
                data:{type:'system_info_change',webname:webname,article_num:article_num,blog_num:blog_num,photo_num:photo_num,skin_num:skin_num,post_num:post_num,reply_num:reply_num},
                dataType:'json',
                success:function(data)
                {
                    if(data.status==1)
                    {
                        $("#system_warming").html(data.msg);
                        $("#system_warming_alert").removeClass('alert-danger').addClass('alert-success');
                        $("#system_warming_alert").show();
                    }
                    else {
                        //显示错误信息
                        $("#system_warming").html(data.msg);
                        $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                        $("#system_warming_alert").show();
                    }
                },
                error:function()
                {
                    //异常显示
                    $("#system_warming").html('网络异常');
                    $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                    $("#system_warming_alert").show();
                }
            });
        });

        //敏感词修改
        $(document).on('click','.chk_word',function () {
            var word_item=$(this).prev('.word_item').val();
            var word_item_old=$(this).data('word');
            if (word_item == '') {
                //显示错误信息
                $("#system_warming").html('敏感词值不能为空');
                $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                $("#system_warming_alert").show();
            }
            else if (word_item_old == '') {
                //显示错误信息
                $("#system_warming").html('数据异常，请刷新页面');
                $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                $("#system_warming_alert").show();
            }
            else {
                $.ajax({
                    type: 'post',
                    url: 'admin_action.php',
                    data: {type: 'system_word_change', word_item: word_item, word_item_old: word_item_old},
                    dataType: 'json',
                    success: function (data)
                    {
                        if (data.status == 1) {
                            $("#system_warming").html(data.msg);
                            $("#system_warming_alert").removeClass('alert-danger').addClass('alert-success');
                            $("#system_warming_alert").show();
                        }
                        else {
                            //显示错误信息
                            $("#system_warming").html(data.msg);
                            $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                            $("#system_warming_alert").show();
                        }
                    },
                    error: function () {
                        //异常显示
                        $("#system_warming").html('网络异常');
                        $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                        $("#system_warming_alert").show();
                    }
                });
            }
        });

        //敏感词删除
        $(document).on('click','.del_word',function () {
            var word_item = $(this).data('word');
            var word_element = $(this).parent().parent('.word-col');
            if (word_item == '') {
                //显示错误信息
                $("#system_warming").html('数据异常，请刷新页面重试');
                $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                $("#system_warming_alert").show();
            }
            else if (!word_element) {
                //显示错误信息
                $("#system_warming").html('已删除，请刷新页面');
                $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                $("#system_warming_alert").show();
            }
            else {
                $.ajax({
                    type: 'post',
                    url: 'admin_action.php',
                    data: {type: 'system_word_delete', word_item: word_item},
                    dataType: 'json',
                    success: function (data)
                    {
                        if (data.status == 1) {
                            $("#system_warming").html(data.msg);
                            $("#system_warming_alert").removeClass('alert-danger').addClass('alert-success');
                            $("#system_warming_alert").show();
                            word_element.remove();
                        }
                        else {
                            //显示错误信息
                            $("#system_warming").html(data.msg);
                            $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                            $("#system_warming_alert").show();
                        }
                    },
                    error: function () {
                        //异常显示
                        $("#system_warming").html('网络异常');
                        $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                        $("#system_warming_alert").show();
                    }
                });
            }
        });

        //敏感词增加
        $(".add_word").click(function () {
            var word_item=$("#word_item").val();
            if (word_item == '') {
                $("#system_warming").html('敏感词不能为空');
                $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                $("#system_warming_alert").show();
            }
            else {
                $.ajax({
                    type: 'post',
                    url: 'admin_action.php',
                    data: {type: 'system_word_add', word_item: word_item},
                    dataType: 'json',
                    success: function (data)
                    {
                        if (data.status == 1) {
                            $("#system_warming").html(data.msg);
                            $("#system_warming_alert").removeClass('alert-danger').addClass('alert-success');
                            $("#system_warming_alert").show();
                            $("#word-form").append('<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6 word-col"><div class="form-group input-group"><input type="text" class="word_item form-control" value="' + word_item + '"><span class="input-group-btn chk_word" data-word="' + word_item + '"><button type="button" class="btn btn-success"><i class=" fa fa-check"></i></button></span><span class="input-group-btn del_word" data-word="' + word_item + '"><button type="button" class="btn btn-danger"><i class="fa fa-times"></i></button></span></div> </div>');
                        }
                        else {
                            //显示错误信息
                            $("#system_warming").html(data.msg);
                            $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                            $("#system_warming_alert").show();
                        }
                    },
                    error: function () {
                        //异常显示
                        $("#system_warming").html('网络异常');
                        $("#system_warming_alert").removeClass('alert-success').addClass('alert-danger');
                        $("#system_warming_alert").show();
                    }
                });
            }
        });
    })
</script>